<?php
namespace Home\Controller;
use Think\Controller;

class BaseController extends Controller{
	//初始化
	protected function _initialize(){
    }
    
    //成功提示
    protected function success($url='',$tip='',$second=3,$type=0){
    	$url = htmlspecialchars_decode($url);
    	if (empty($tip)){
    		header('Location:'.$url);
			exit;
    	}else{
			if (in_array($type,array(0,2))){
				$this->assign('Refresh',$second);
				$this->assign('Url',$url);
				$this->assign('Kind','success');
				$this->assign('Tip',$tip);
				$this->assign('Type',$type);
				$this->assign('A','如果您的浏览器没有自动跳转，请点击这里');
				$this->assign('Run',"<script type=\"text/javascript\">var run=window.parent.document.getElementById('run');if(run!=null)run.innerHTML='执行耗时：'+".(_runtime()-START_TIME)."+'秒';</script>");
				$this->display(C('TMPL_ACTION_SUCCESS'));
				exit;
			}elseif ($type == 1){
				exit("<script type=\"text/javascript\">alert('$tip');parent.location.href='$url';</script>");
			}else{
				$this->success($url,$tip,$second,0);
			}
    	}
    }
    
    //错误提示
    protected function failed($tip='',$second=5,$type=0,$url=''){
    	$url = htmlspecialchars_decode($url);
		$this->assign('Refresh',$second);
		$this->assign('Url',$url);
		$this->assign('Kind','failed');
		$this->assign('Tip',$tip);
		$this->assign('Type',$type);
		if ($type == 0){
			$this->assign('A','点击这里返回上一页');
		}elseif ($type == 1){
			$this->assign('A','如果您的浏览器没有自动跳转，请点击这里');
		}
		$this->assign('Run',"<script type=\"text/javascript\">var run=window.parent.document.getElementById('run');if(run!=null)run.innerHTML='执行耗时：'+".(_runtime()-START_TIME)."+'秒';</script>");
		$this->display(C('TMPL_ACTION_ERROR'));
		exit;
    }
}